package one;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

@SuppressWarnings("deprecation")
public class Multiplewindows extends SeleneseTestCase {
	public SeleniumServer bm;
	@Before
	public void setUp() throws Exception {
		bm=new SeleniumServer();
		bm.start();
		selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.bitmotif.com/");
		
		selenium.start();
	}



	@Test
	public void testUntitled() throws Exception {
		//open the url in the browser
		selenium.open("/");
		//maximize the window
		selenium.windowMaximize();
		//click on the link test page for selenium remote control
		selenium.click("link=Test Page For Selenium Remote Control");
		selenium.waitForPageToLoad("30000");
		//select the dropdown
		selenium.select("id=selectWithLabelsOnly","label=option two");
		//check the checkbox
		selenium.check("id=checkBoxInput");
		//type something in the box
		selenium.type("id=textInput","webdrivers");
		//click on the new window link
		selenium.click("link=This link opens a popup");
		//to know the name of the new window
		String a[]=	selenium.getAllWindowIds();
		for (int i = 0; i < a.length; i++) 
		{
		System.out.println("window IDs are "+a[i]);	
		}
		
		String b[]=	selenium.getAllWindowNames();
		for (int i = 0; i < b.length; i++) 
		{
		System.out.println("window Names are "+b[i]);	
		}
		
		String c[]=	selenium.getAllWindowTitles();
		for (int i = 0; i < c.length; i++) 
		{
		System.out.println("window Titles are "+c[i]);	
		}
		//wait for new window
		selenium.waitForPopUp("popup","30000");
		//select the new child window
		selenium.selectWindow("popup");
		//focus to child window
		selenium.windowFocus();
		//click abount in child window
		selenium.click("link=About");
		Thread.sleep(5000);
		//closing the child window
		selenium.close();
		//select the parent window
		selenium.selectWindow(null);
		//focus on main window
		selenium.windowFocus();
		//click About in parent window
		selenium.click("link=About");
		Thread.sleep(5000);
		
		//goback to homepage
		selenium.goBack();
		//select the dropdown 2
		selenium.select("id=selectWithLabelsAndValues","label=option three");
		//select radiobutton
		selenium.click("name=radioButton");
		//click on reset
		selenium.click("//input[@type='reset']");
		
		Thread.sleep(5000);
		
		
		
			
		
			}

	@After
	public void tearDown() throws Exception {
		selenium.stop();
		bm.stop();
	}
}

